package com.budwk.app.sqfwV2.generator.enterpriseWarrantyServe.excel;


import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.budwk.app.sqfw.constants.CommonConstants;
import com.budwk.app.sqfwDoc.bo.SqfwExcelForSummaryBO;
import com.budwk.app.sqfwDoc.bo.SqfwExcelJudgeRes;
import com.budwk.app.sqfwDoc.codeGenerator.excelGenerate.BaseExcelParamDTO;
import com.budwk.app.sqfwDoc.codeGenerator.excelGenerate.BaseTemplateExcelGenerator;
import com.budwk.app.sqfwDoc.codeGenerator.excelGenerate.SqfwExcelCreateCommonBO;
import com.budwk.app.sqfwV2.dto.EnterpriseWarrantyServeDTO;
import com.budwk.app.sqfwV2.dto.image.PublicSecurityExcelImageConfigBO;
import com.budwk.app.sqfwV2.enums.enterpriseWarrantyServe.EnterpriseWarrantyServeFileEnum;
import com.budwk.app.sys.models.Sys_user;
import com.budwk.app.sys.services.SysUserService;
import com.budwk.app.util.StrUtil;
import com.budwk.app.util.poiUtils.excelPictureConfigBO.ExcelFileCreateParamBO;
import com.budwk.app.util.poiUtils.nutzBeanUtils.NutzIocUtils;
import org.apache.commons.lang3.StringUtils;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author 东方祥云低代码1.1
 * @since 2024-03-25
 * <p>
 * 大营路社会治安 1
 * 【社会治安重点风险场所】台账.xlsx
 */
public class EnterpriseAppealExcelGenerator extends BaseTemplateExcelGenerator {

    @Override
    protected void customerPopularSheetBaseParam(Map<String, Object> excelParam, SqfwExcelCreateCommonBO excelCreateParam) {
        BaseExcelParamDTO b = excelCreateParam.getBaseExcelParamDTO();
        SysUserService userService = NutzIocUtils.getBean(SysUserService.class);
        Sys_user user = userService.fetch(b.getCreateUserId());
        String unitName = "";

        if (!CommonConstants.DIRECTLY_UNDER.equals(user.getDistrict())) {
            unitName += user.getDistrict();
        }
        if (!CommonConstants.DIRECTLY_UNDER.equals(user.getCounty())) {
            unitName += user.getCounty();
        }
        if (!CommonConstants.DIRECTLY_UNDER.equals(user.getCommunity())) {
            unitName += user.getCommunity();
        }
        excelParam.put("unitName", unitName);
    }

    @Override
    protected void customerPopularSheetDataParam(List<Map<String, Object>> listMap, SqfwExcelCreateCommonBO excelCreateParam) {

    }

    @Override
    protected String getTemplateName() {
        return EnterpriseWarrantyServeFileEnum.ENTERPRISE_APPEAL_BOOK.getTemplatePath();
    }

    @Override
    public String getDownloadFileName() {
        return EnterpriseWarrantyServeFileEnum.ENTERPRISE_APPEAL_BOOK.getName() + "_" + DateUtil.format(new Date(), "yyyyMMddHHmmss");
    }

    /**
     * 允许用户在创建excel文件之前对配置进行修改
     *
     * @param excelFileCreateParamBO 创建excel的配置参数
     */
    @Override
    protected void completeExcelFileCreateParam(ExcelFileCreateParamBO excelFileCreateParamBO) {

    }

    @Override
    protected void customerPopularRowDataMap(Map<String, Object> rowDataMap, SqfwExcelForSummaryBO forSummaryBO) {
        EnterpriseWarrantyServeDTO enterpriseWarrantyServeDTO = JSONObject.parseObject(forSummaryBO.getSqfwFormSummaryNew().getParamData(), EnterpriseWarrantyServeDTO.class);
        rowDataMap.put("whetherToSolve", "true".equals(enterpriseWarrantyServeDTO.getWhetherToSolve()) ? "是" : "否");
        rowDataMap.put("fillDateStr", DateUtil.format(enterpriseWarrantyServeDTO.getFillDate(), "yyyy-MM-dd HH:mm"));
        rowDataMap.put("claimResolutionTime", DateUtil.format(enterpriseWarrantyServeDTO.getClaimResolutionTime(), "yyyy-MM-dd HH:mm"));

    }

    @Override
    protected SqfwExcelJudgeRes judgeDataIntoExcelBeforeErgodic(SqfwExcelCreateCommonBO excelCreateParam, Map<String, Object> excelParam) {
        return null;
    }

    @Override
    protected SqfwExcelJudgeRes judgeDataIntoExcelBeforeCreate(Map<String, Object> excelParam) {
        return null;
    }

    @Override
    protected Class<?> getImageConfigBO() {
        return PublicSecurityExcelImageConfigBO.class;
    }
}
